<template>
    <div class="dialog">
        <div class="dialog-con complaintReturnInfo">
            <div class="com">退货入库商品详情</div>
            <div class="numberContent">
                <ul class="number">
                    <li style="flex:1.5">商品名称</li>
                    <li>退货数量</li>
                    <li>破损数量</li>
                </ul>
                <ul class="name" v-for="(item,index) in items.items" :key="index">
                    <li style="flex:1.5">{{item.itemSkuName}}</li>
                    <li>{{item.returnNum}}</li>
                    <li><el-input-number  size="small" v-model="items.items[index].brokenNum"  controls-position="right" @change="handleChange($event,item.itemId)" :min="0" :max="250">{{item.brokenNum}}</el-input-number></li>
                </ul>
            </div>
            <div class="btn">
                <el-button size="medium" @click="importSystem">确定</el-button>
                <el-button size="medium" @click="cancel">取消</el-button>
            </div>
        </div>
    </div>
</template>

<script>
import {localStorage} from 'js/localStorage'
import api from 'js/service'
export default {
    inject:['reload'],
    data(){
        return{
           
        }
    },
    props:{
        items:{
            type:Object,
            default:{}
        }
    },
    created(){
        this.userId=localStorage.get('userID')
    },
    methods:{
        cancel(){
            this.$emit('closeDialog')
        },
        importSystem(){
            var arr=[]
            for(var item of this.items.items){
                if(item.returnNum < item.fixNum){
                    return this.$message.warning("破损数量不能大于退货数量")
                }
            //    if(item.fixNum == undefined){
            //        item.fixNum=0
            //    }
                var obj={
                    id: item.id,
                    itemId: item.itemId,
                    returnNum:item.returnNum,
                    brokenNum: item.fixNum || 0
                }
                arr.push(obj)
            }
            let parmas={           
                complainId:this.items.complainId,
                items:arr
            }
            let success=data=>{
                if(data.code=='OK'){
                    this.$message.success(data.msg)
                    this.$emit("closeDialog")
                    this.reload()
                }else{
                    this.$message.error(data.msg)
                }
            }
            api.erpOrderReturnStockIn(parmas,success)  
        },
        handleChange(num,id){
            for(let item of this.items.items){
                if(item.itemId == id){
                    item.fixNum = num;
                }
            }
        }  
    }
}
</script>
<style lang="scss" scoped>
.complaintReturnInfo{
    width:550px;
    height:500px;
    .com{
        line-height:45px;
        background: #eee;
        text-align: center;
        margin-bottom:20px;
    }
    .numberContent{
        height:370px;
        .number{
            display: flex;
            li{
                flex:1;
                text-align: center;
                line-height: 35px;
                font-size:16px;
                color:#606266;
            }
        }
        .name{
            display: flex;
            li{
                flex:1;
                text-align: center;
                line-height: 35px;
                font-size:14px;
                color:#606266;
            } 
        }
    }
    .btn{
        width:100%;
        text-align:center;
    }

}
</style>

